package com.example.demo.service.impl;

import com.example.demo.entity.request.uiTestCaseStepReq.UITestCaseStepAddReq;
import com.example.demo.mapper.UICaseStepMapper;
import com.example.demo.entity.UICaseStep;
import com.example.demo.service.UICaseStepService;
import com.example.demo.utils.DateToStamp;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

@Service
public class UICaseStepServiceImpl implements UICaseStepService {
    @Resource
    UICaseStepMapper uiCaseStepMapper;

    @Override
    public int insert(List<UITestCaseStepAddReq> uiTestCaseStepAddReqs) {
        AtomicInteger sort = new AtomicInteger(0);
        uiTestCaseStepAddReqs.forEach(uiTestCaseStepAddReq -> {
            UICaseStep uiCaseStep =new UICaseStep();
            BeanUtils.copyProperties(uiTestCaseStepAddReq,uiCaseStep);
            uiCaseStep.setSort(sort.incrementAndGet());
            uiCaseStep.setCreateTime(DateToStamp.getTimeStampLong());
            uiCaseStep.setUpdateTime(DateToStamp.getTimeStampLong());
            uiCaseStepMapper.insert(uiCaseStep);
        });
        return sort.get();
    }

    @Override
    public List<UICaseStep> findByTestCaseId(Long uiTestCaseId) {
        return uiCaseStepMapper.findByTestCaseId(uiTestCaseId);
    }

    @Override
    public int updateUICaseStep(UICaseStep uiCaseStep) {
        uiCaseStep.setUpdateTime(DateToStamp.getTimeStampLong());
        return uiCaseStepMapper.updateUICaseStep(uiCaseStep);
    }

    @Override
    public int deleteStepById(Long id) {
        return uiCaseStepMapper.deleteStepById(id);
    }


}
